package cn.exrick.xboot.quartz.jobs.distributedLock;

import cn.exrick.xboot.quartz.jobs.distributedLock.entity.Lock;
import cn.exrick.xboot.quartz.jobs.distributedLock.utils.DistributedLockHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class test {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private StringRedisTemplate template;

    @Autowired
    DistributedLockHandler distributedLockHandler;

    public void testDistributed(){

        Lock lock=new Lock("testlock","lockvalue");
        if(distributedLockHandler.tryLock(lock)){
            /*try {
                Thread.sleep(40000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }*/
            logger.info("everOne start...");
            System.out.println("template   --"+template);
            System.out.println("distributedLockHandler   --"+distributedLockHandler);
            //statusTask.healthCheck();
            // int i=10/0;
            logger.info("everOne end...");
            distributedLockHandler.releaseLock(lock);
        }

    }

}
